
const BaseUrl = '/'

let loginTimer = null

function post(url, params, _config) {
    let config = Object.assign({
        token: true, //默认不需要token参数
        check: true, //默认要判断返回的状态,
        responseType: 'json'
    }, _config);

    if (config.token) {
        // params.token = getToken()
    }

    return new Promise((resolve, reject) => {
        axios.post(BaseUrl + url, params, {
            responseType: config.responseType, headers: {
                'Content-Type': 'application/json'
            }, transformRequest: [function (data) {
                data = JSON.stringify(data)
                return data
            }],
        })
            .then(res => {
                if (config.check) {
                    if (res.data.success !== 'true') {
                        App.$message.error(res.data.message || '未知错误')
                        reject(res);
                    } else {
                        resolve(res.data);
                    }
                } else {
                    resolve(res.data);
                }
            })
            .catch(err => {
                // reject(err.data)
                App.$message.error('请求服务器失败')
                reject(err);
            })
    });
}

function get(url, params) {
    return new Promise((resolve, reject) => {
        // params.token = getToken()
        let q = '?'
        for (let k in params) {
            q += `${k}=${params[k]}&`
        }
        axios.get(BaseUrl + url + q, params)
            .then(res => {
                if (res.data.success !== 'true') {
                    App.$message.error(res.data.message || '未知错误')
                    reject(res);
                } else {
                    resolve(res.data);
                }
            })
            .catch(err => {
                App.$message.error('请求服务器失败')
                reject(err.data)
            })
    });
}


// 接口列表
// const api_userSign = (params) => post('api/user/sign', params, {}); // 每日签到
const api_getUserInfo = () => get('api/uc/getUserInfo', {}, {});
const api_getLevelList = () => get('api/uc/getLevelList', {}, {});
const api_getInviteeList = () => get('api/uc/getInviteeList', {}, {});
const api_getLastGame = () => get('api/uc/getLastGame', {}, {});
const api_loginOut = () => post('api/uc/loginOut', {}, {});
const api_commitYj = (p) => post('api/uc/commitYj', p, {});
const api_realName = (p) => post('api/uc/realName', p, {});
const api_wfIntegralList = (p) => get('api/uc/wfIntegralList', p, {});
const api_refreshUserInfo = () => post('api/uc/refreshUserInfo', {}, {});
const api_getInviteCode = () => get('api/uc/getInviteCode', {}, {});
const api_getNeedBindKf = () => get('api/uc/getNeedBindKf', {}, {});
const api_getKfQrCode = (p) => get('api/uc/getKfQrCode', p, {});
const api_bindMobile = (p) => post('bindMobile', p, {});
const api_getSmsCode = (p) => post('getSmsCode', p, {});

const api_getDhGameList = (p) => get('api/dh/getGames', p, {});
const api_getDhGameById = (p) => get('api/dh/getGameById', p, {});
const api_getDhServerList = (p) => get('api/dh/getServerList/'+p.id, {}, {});
const api_commitDh = (p) => post('api/dh/commitDh', p, {});
const api_getDhLog = () => get('api/dh/getDhLog', {}, {});

const api_getRechargeReward = (p) => get('api/pay/getRechargeReward', p, {});
const api_getRechargeRules = () => get('api/pay/getRules', {}, {});
const api_rechargePay = (p) => post('api/pay/rechargePay', p, {});
const api_getRechargeLog = () => get('api/pay/getRechargeLog', {}, {});
const api_getRechargeLogByUser = (p) => get('api/pay/getRechargeLogByUser', p, {});
const api_getOrderStatus = (p) => get(`api/pay/getOrderStatus/${p.type}/${p.orderId}`, {}, {});


const api_getGoods = () => get('api/shop/getGoods', {}, {});
const api_getAddress = () => get('api/shop/getAddress', {}, {});
const api_saveAddress = (p) => post('api/shop/saveAddress', p, {});
const api_delAddress = (p) => post('api/shop/delAddress', p, {});
const api_shopOrderList = () => get('api/shop/orderList', {}, {});
const api_integralList = () => get('api/shop/integralList', {}, {});
const api_shopCreateOrder = (p) => post('api/shop/createOrder', p, {});

const api_activateGetLbInfo = () => get('api/activate/getLbInfo', {}, {});
const api_activateGetLbReward = (p) => post('api/activate/getLbReward', p, {});
const api_activateGetLevelRewardInfo = (p) => get('api/activate/getLevelRewardInfo', p, {});
const api_activateGetLevelReward = (p) => post('api/activate/getLevelReward', p, {});
const api_activateGetLevelDhqList = (p) => get('api/activate/getLevelDhqList', p, {});
const api_activateUseLevelDhq = (p) => post('api/activate/useLevelDhq', p, {});


const api_gameRecharge = (p) => post('gameRecharge', p, {});
